# -*- coding: utf-8 -*-
# @Time : 2023/12/26 22:48
# @Author : Lpb
# @File : flask_study_server.py
from flask import Flask, request, jsonify
# Flask 应用实例化：（是flask使用的约定）
app = Flask(__name__)
# 初始化列表：
res = []

# 路由装饰器和定义：
@app.route('/push', methods=['post'])
def push():
    # 获取request的结构的数据
    data = request.json
    try:
        msg = data['msg']
    except KeyError:
        return jsonify({"msg": "data error"}), 403
    res.append(msg)
    return jsonify({"msg": "push success"}), 200


@app.route('/pull', methods=['get'])
def pull():
    global res
    response = {'msg': 'pull success', 'data': res}
    res = []
    return jsonify(response), 200


if __name__ == '__main__':
    app.run(host='127.0.0.1', port=8888, debug=True)